import $store from '@/store/index.js';
import groupApi from "@/services/api/group.js"
import groupSqlite from "@/sqlite_services/group.js"
import groupMembersSqlite from '@/sqlite_services/group_members.js'
//群内昵称修改
const handle = async(data)=>{
	try{
		let myid = $store.state.user.user_info.user_id
		if(myid == data.user_id){
			$store.commit('updateChatGroupInfo',{
				group_id:data.target_id,
				userNickname:data.group_nickname
			})
			//更新数据库里的我的身份
			groupSqlite.editGroupInfo(data.target_id,{
				userNickname:data.group_nickname
			})
		}
		//更新群成员资料
		$store.commit('updateGroupMembersInfo',{
			group_id:data.target_id,
			data:{ user_id: data.user_id, group_nickname:data.group_nickname }
		})
		//更新数据库群成员资料
		groupMembersSqlite.editGroupMembers(data.target_id,data.user_id,{group_nickname:data.group_nickname})
		//发送全局通知
		uni.$emit('onGroupMemberAction',{
			type:'member_nick',
			data:{
				group_id:data.target_id,
				user_id:data.user_id,
				group_nickname:data.group_nickname
			}
		})
	}catch(e){
		
	}
}
export default handle